package com.dundun.pattern.interpreter;

import java.util.ArrayList;
import java.util.List;

public class CommandListNode implements Node {

    private List<Node> list = new ArrayList<>();

    @Override
    public void parse(Context context) throws ParseException {
        while (true) {
            if(context.currentToken() == null) {
                throw new ParseException("missing end.");
            } else if(context.currentToken().equals("end")) {
                context.skipToken("end");
                break;
            } else {
                Node node = new CommandNode();
                node.parse(context);
                list.add(node);
            }
        }
    }

    @Override
    public String toString() {
        return list.toString();
    }
}
